<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8" />
        <title>Filter - ESUI Demo</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../dep/esui/3.2.0-beta.2/demo/assets/google-code-prettify/prettify.css"/>
        <link rel="stylesheet" href="assets/themes/standard.css" />
        <!--[if lt IE 9]>
        <link rel="stylesheet" href="../dep/esui/3.2.0-beta.2/demo/assets/ie8.css"/>
        <![endif]-->
    </head>
<body>
    <div class="header">
        <h1 id="branding">ESUI Filter</h1>
    </div>
    <div class="ui-g main-container">
        <div id="side-bar" class="ui-u-1-5">
            <ul id="navigator" class="ui-nav">
            </ul>
        </div>
        <div id="main" class="ui-u-4-5">
            <h2>FilterGroup</h2>
            <p>FilterGroup</p>
            <div class="example" id="container">
                <div data-ui-type="Filter"
                     data-ui-id="test1"
                     data-ui-custom="true"
                     data-ui-label="单选："
                     data-ui-value="SHANGHAI0">
                </div>
                <div data-ui-type="Filter"
                     data-ui-id="test2"
                     data-ui-label="多选："
                     data-ui-custom="true"
                     data-ui-multiple="true">
                </div>
                <div data-ui-type="FilterResult"
                     data-ui-id="result"
                     data-ui-label="已选择：">
                </div>
                <div data-ui-type="Button" data-ui-id="submit" data-ui-variants="success" style="margin-top:20px;">获取值</div>
            </div>
            <script type="text/sample" data-refid="main-js">
            </script>
        </div>
    </div>
    <script src="../dep/esui/3.2.0-beta.2/demo/assets/loader/esl.js"></script>
    <script src="config.js"></script>
    <script src="../dep/esui/3.2.0-beta.2/demo/demo.js"></script>
    <script src="../dep/esui/3.2.0-beta.2/demo/assets/google-code-prettify/prettify.js"></script>
    <script id="main-js">
    require(
        [
            'jquery',
            'esui',
            'ub-ria-ui/filter/Filter',
            'ub-ria-ui/filter/FilterResult',
            'esui/Button',
            'demo',
            'esui/Tab'
        ],
        function ($, ui) {
            window.ui = ui;
            var citys = [
                {
                    text: '上海',
                    value: 'SHANGHAI'
                },
                {
                    text: '北京',
                    value: 'BEIJING'
                },
                {
                    text: '广州',
                    value: 'GUANGZHOU'
                },
                {
                    text: '深圳',
                    value: 'SHENZHEN'
                },
                {
                    text: '杭州',
                    value: 'HANGZHOU'
                },
                {
                    text: '南京',
                    value: 'NANJING'
                },
                {
                    text: '厦门',
                    value: 'XIAMEN'
                },
                {
                    text: '苏州',
                    value: 'SUZHOU'
                },
                {
                    text: '珠海',
                    value: 'ZHUHAI'
                }
            ];
            var controls = ui.init();
            $.each(controls, function (index, control) {
                if (index + 2 >= controls.length) {
                    return;
                }
                var citysClone = $.extend(true, [], citys);
                $.each(citysClone, function (i, city) {
                    city.text += index;
                    city.value += index;
                });
                control.setProperties({
                    datasource: citysClone
                });
            });
            var filter1 = controls[0];
            var filter2 = controls[1];
            var result = controls[2];
            filter1.on('change', function (e) {
                if (e.action === 'select') {
                    result.addItem(e.item);
                    result.removeItem(e.lastItem);
                }
                else {
                    result.removeItem(e.item);
                }
            });
            // 保存自定义时监听
            filter1.on('custom-link-click', function () {
                this.addItem({text: 'text', value: 'value', allowDelete: true});
            });
            // 监听自定义选项的remove动作
            filter1.on(
                'custom-item-remove',
                function (e) {
                    result.removeItem(e.item);
                }
            );
            filter2.on('change', function (e) {
                if (e.action === 'select') {
                    result.addItem(e.item);
                }
                else {
                    result.removeItem(e.item);
                }
            });
            result.on('change', function (e) {
                filter1.unselectItem(e.item);
                filter2.unselectItem(e.item);
            });
            // 获取值
            var submit = controls[3];
            submit.on('click', function (e) {
                // var val = filter1.getValue();
            });
        }
    );
    </script>
    <script src="sitemap.js"></script>
</body>
</html>
